import fs from 'fs';
import path from 'path';
import { Collection } from './Collection';

let {
	dir,
	root,
	extension
} = require('./conf');

async function createCollection(name) {
	let filepath = path.join(root,name+extension);
	let exists = fs.existsSync(filepath);
	if (!exists) {
		await fs.writeFile(filepath,JSON.stringify([]));
	}
	var col=new Collection(name);
	return col;
}

async function registCollection(names){
	let cx = this.context;
	cx.locServe={};
	for(let i=0;i<names.length;i++){
		cx.locServe[names[i]] = await createCollection(names[i]);
	}
}
export default registCollection;